package properties_package;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class properties_demo2 {
    public static void main(String[] args) throws IOException {
        /*
            Properties跟IO流结合的操作
         */

        //1、创建集合
        Properties prop = new Properties();

        //2、添加数据
        prop.put("aaa","bbb");
        prop.put("bbb","333");
        prop.put("ccc","222");
        prop.put("fff","bbb");

        //3、把集合中的数据以键值对的形式写到本地文件当中
        BufferedWriter bw = new BufferedWriter(new FileWriter("/Users/zhaoxiaoyong/Documents" +
                "/Java/jigsaw_puzzle_project/properties_module/src/properties_package/a.txt"));

        Set<Map.Entry<Object, Object>> entries = prop.entrySet();
        for (Map.Entry<Object, Object> entry : entries) {
            Object key = entry.getKey();
            Object value = entry.getValue();

            bw.write(key+"="+value);
            bw.newLine();

        }
        bw.close();

        //另一种方式
        FileOutputStream fos = new FileOutputStream("/Users/zhaoxiaoyong/Documents" +
                "/Java/jigsaw_puzzle_project/properties_module/src/properties_package/a.txt");
        prop.store(fos,"test");
        fos.close();

    }
}
